<?php
  require_once 'controle/atualizarvideos.php';
  include "conexao.php";
?>
<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="utf-8">
    <title>FaceTube - Adicionar Canal</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="description" content="">
    <meta name="author" content="rodrigo"/>
    

    <!--Importando css e js bootstrap -->
    <link rel="stylesheet" href="css/bootstrap.css">
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/bootstrap.js"></script>

    <!--Importando jquery-->
    <script type="text/javascript" src="js/jquery.validate.js"></script>
    <link rel="stylesheet" href="js/ui-1.10.4/css/ui-start.css">
    <script type="text/javascript" src="js/ui-1.10.4/js/jquery-ui.js"></script>
    
    

  </head>
  
  <body>
    <div class="container">
      <div class="row">
      <h1>Atualizar Videos</h1>
        <table class="table table-condensed table-striped">
          <thead>
            <tr>
              <th>N°</th>
              <th>Canal</th>
              <th>Status</th>
            </tr>
          </thead>
          <tbody>
      


<?php
  
  $canais = array();
  $c = getCanais();
  $i = 0;
  while($row = mysql_fetch_array($c)){
    $canais[$i]['id'] = $row['ytid'];
    $canais[$i]['nome'] = stripslashes($row['ytusername']);
    $canais[$i]['titulo'] = stripslashes($row['yttitulo']);
    $udata = getData($canais[$i]['id']);
    $canais[$i]['udata'] = $udata[0];
    $i = $i+1;
  }
  $nr = 0;

  for ($i=0; $i < count($canais); $i++) { 
      $nr = $nr+1;
      $v = getVideos($canais[$i]['nome'],$canais[$i]['udata']);
      $msg = "";
      if (gettype($v) == "integer"){
        $msg = "Erro ao adquirir feed";
        echo "<script>alert(\"erro\");</script>";
      }else{
        $r = setVideos($canais[$i]['id'], $v);

        if($r == -1){
          $msg = "Erro ao inserir video no banco";
        }else{
          $msg = count($v)." VIDEOS ATUALIZADOS";
        }
      }
      echo "
        <tr>
          <td>".$nr."</td>
          <td>".$canais[$i]['titulo']."</td>
          <td>".$msg."</td>
        </tr>
      ";
  }

?>

          </tbody>
        </table>
        <h1>10:00</h1>
        <?php echo "<meta HTTP-EQUIV='refresh' CONTENT='600;URL=upvideo.php'>"; ?>
      </div>
    </div>
    
  </body>
</html>